home *** CD-ROM | disk | FTP | other *** search
/ NeXT Education Software Sampler 1992 Fall / NeXT Education Software Sampler 1992 Fall.iso / Programming / Classes / XText / XTDemo.m < prev    next >
Encoding:
Text File  |  1992-04-14  |  2.0 KB  |  88 lines

  1. /*    This file is part of the XText package (version 0.8)
  2.     Mike Dixon, April 1992
  3.     
  4.     Copyright (c) 1992 Xerox Corporation.  All rights reserved.
  5.  
  6.     Use and copying of this software and preparation of derivative works based
  7.     upon this software are permitted.  This software is made available AS IS,
  8.     and Xerox Corporation makes no warranty about the software or its
  9.     performance.
  10. */
  11.  
  12. #import "XTDemo.h"
  13. #import <appkit/Control.h>
  14. #import <appkit/Font.h>
  15. #import "XTScroller.h"
  16. #import "XText.h"
  17. #import "ErrorStream.h"
  18.  
  19. @implementation XText(XTDemo_extras)
  20. - insertKeyCombination:(NXEvent *)event
  21. {
  22.     char code[6];
  23.     int code_len = 0;
  24.     int last_digit = event->data.key.keyCode & 0xf;
  25.  
  26.     if (event->flags & NX_CONTROLMASK)   code[code_len++] = 'c';
  27.     if (event->flags & NX_SHIFTMASK)     code[code_len++] = 's';
  28.     if (event->flags & NX_ALTERNATEMASK) code[code_len++] = 'a';
  29.     if (event->flags & NX_COMMANDMASK)   code[code_len++] = 'm';
  30.     code[code_len++] = '0' + (event->data.key.keyCode >> 4);
  31.     code[code_len++] = (last_digit < 10) ? '0'+last_digit : 'a'+last_digit-10;
  32.     [self replaceSel:code length:code_len];
  33.     return self;
  34. }
  35.  
  36. - insertKeyCombOfNextKey
  37. {
  38.     static id action = nil;
  39.  
  40.     if (!action)
  41.         action = [[XTEventMsgAction alloc]
  42.                         initSel:@selector(insertKeyCombination:)];
  43.     nextAction = action;
  44.     return self;
  45. }
  46. @end
  47.  
  48. @implementation XTDemo
  49.  
  50. - init
  51. {
  52.     [super init];
  53.     initialAction = [[XTDispatchAction alloc] initBase:"" estream:nil];
  54.     [initialAction addBindings:"c'Q=insertKeyCombOfNextKey"
  55.                    estream:nil];
  56.     return self;
  57. }
  58.  
  59. - doIt:sender
  60. {
  61.     [initialAction addBindings: [cmdField stringValue]
  62.                    estream:[xtext errorStream]];
  63.     return self;
  64. }
  65.  
  66. - appDidInit:sender
  67. {
  68.     id my_font = [Font newFont:"Ohlfs" size:14.0];
  69.     
  70.     [cmdField setFont:my_font];
  71.     
  72.     xtext = [xtext docView];
  73.     [xtext setFont:my_font];
  74.     [xtext setInitialAction:initialAction];
  75.     [xtext setSel:0 :0];
  76.     [[xtext window] makeKeyAndOrderFront:self];
  77.     return self;
  78. }
  79.  
  80. - windowWillReturnFieldEditor:sender toObject:client
  81. {
  82.     return [XText newFieldEditorFor:sender
  83.                     initialAction:initialAction
  84.                     estream:nil];
  85. }
  86.  
  87. @end
  88.